home *** CD-ROM | disk | FTP | other *** search
- { * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- Purpose: Create a new Object ID (OID) which will be unique within
- the database.
-
- Revision History:
- Sept 1999, PWH, Created
-
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * }
-
- { ToDo 1 -cBOM: Break NextOID into two (or three?) units }
-
- unit DBNextOID;
-
- interface
- uses
- classes
- ,tiPtnVisitor
- ,tiPtnVisitorDB
- ,tiPtnVisitorMgr
- ;
-
- type
-
- TNextOID = class( TVisitedAbs )
- private
- FIntHigh : integer ;
- FIntLow : integer ;
- function GetNextOID : integer ;
- public
- constructor create ; override ;
- property NextOID : integer read GetNextOID ;
- property NextOIDHigh : integer read FIntHigh write FIntHigh ;
- end ;
-
- TVisGetNextOID = class( TVisDBSelect )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- procedure MapRowsToObject ; override ;
- public
- end ;
-
- TVisIncNextOID = class( TVisDBUpdate )
- protected
- function AcceptVisitor : boolean ; override ;
- procedure Init ; override ;
- public
- end ;
-
- function gNextOID : TNextOID ;
-
- implementation
- uses
- cAdrs
- ,SysUtils
- ;
-
- const
- cuiLow = 10 ;
-
- var
- uNextOID : TNextOID ;
-
- //------------------------------------------------------------------------------
- function gNextOID : TNextOID ;
- begin
- if uNextOID = nil then
- uNextOID := TNextOID.Create ;
- result := uNextOID ;
- end ;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TNextOID
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- constructor TNextOID.create;
- begin
- inherited create ;
- FIntHigh := 0 ;
- FIntLow := 0 ;
- end;
-
- //------------------------------------------------------------------------------
- function TNextOID.GetNextOID: integer;
- begin
- if FIntHigh = 0 then
- gVisitorCache.Execute( cgsGetNextOIDHigh, self ) ;
-
- result := FIntHigh * cuiLow + FIntLow ;
-
- inc( FIntLow ) ;
- if FIntLow >= cuiLow-1 then begin
- FIntHigh := 0 ;
- FIntLow := 0 ;
- end ;
-
- end;
-
-
- //------------------------------------------------------------------------------
- function TVisGetNextOID.AcceptVisitor: boolean;
- begin
- result := ( Visited is TNextOID ) ;
- end;
-
- procedure TVisGetNextOID.Init;
- begin
- Query.SQL.Text := 'select Next_OID from Next_OID' ;
- end;
-
- procedure TVisGetNextOID.MapRowsToObject;
- begin
- TNextOID( Visited ).NextOIDHigh := Query.FieldByName( 'Next_OID' ).AsInteger ;
- end;
-
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- // *
- // * TVisIncNextOID
- // *
- // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- function TVisIncNextOID.AcceptVisitor: boolean;
- begin
- result := ( Visited is TNextOID ) ;
- end;
-
- procedure TVisIncNextOID.Init;
- begin
- Query.SQL.Text := 'update Next_OID set Next_OID = Next_OID + 1' ;
- end;
-
- initialization
- gVisitorCache.RegisterVisitor( cgsGetNextOIDHigh, TVisGetNextOID ) ;
- gVisitorCache.RegisterVisitor( cgsGetNextOIDHigh, TVisIncNextOID ) ;
-
- finalization
- uNextOID.Free ;
-
- end.
-
-